package com.example.testapplication.adapter;

import android.content.Context;
import android.text.Layout;
import android.view.LayoutInflater;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.testapplication.R;
import com.example.testapplication.entity.Menu;

import java.util.List;

public class SecondMenuAdapter extends RecyclerView.Adapter<SecondMenuViewholder> {
    protected Context context;
    protected List<Menu> menus;

    public SecondMenuAdapter(Context context,List<Menu> menus){
        this.context = context;
        this.menus = menus;
    }

    @NonNull
    @Override
    public SecondMenuViewholder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new SecondMenuViewholder(LayoutInflater.from(context).inflate(R.layout.item_second_menu,null));
    }

    @Override
    public void onBindViewHolder(@NonNull SecondMenuViewholder holder, int position) {
       Menu menu = menus.get(position);
       holder.sImgMenuIcon.setImageResource(menu.icon);
       holder.sTxtMenuName.setText(menu.menuName);

    }

    @Override
    public int getItemCount() {
        return null!=menus?menus.size():0;
    }
}

class SecondMenuViewholder extends RecyclerView.ViewHolder{
    public ImageView sImgMenuIcon;
    public TextView sTxtMenuName;
    public SecondMenuViewholder(View itemView){
        super(itemView);
        sImgMenuIcon = (ImageView) itemView.findViewById(R.id.second_menu_icon);
        sTxtMenuName = (TextView) itemView.findViewById(R.id.second_menu_name);

    }
}
